/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import simplemetrosystem.control.Calculation.CalculManager;
import simplemetrosystem.control.Calculation.ModelManager;
import simplemetrosystem.model.charlanguage.NameMap;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.view.MetroFrame;
import simplemetrosystem.view.table.Exceptions.InformationPanelException;

/**
 *
 * @author Eric Qian
 */
public class CalculActionListener implements ActionListener {

    public CalculActionListener(MetroFrame frame) {
        this.frame = frame;
        nameMap = NameMap.getInstance();
    }

    public void actionPerformed(ActionEvent e) {
        try {
            if (isMap()) {
                ModelManager.getInstance().setModel(true);
                frame.getInfPane().setFocus(InformationPane.CALCUL, null);
            }
        } catch (InformationPanelException ex) {
            ex.printStackTrace();
        }
    }

    public boolean isMap() {
        if (CalculManager.getInstance().isMap()) {
            //JOptionPane.showMessageDialog(frame,
            //        nameMap.getName("Map is calculable ^-^"),
             //       nameMap.getName("Information"), JOptionPane.INFORMATION_MESSAGE);
            return true;
        } else {
            JOptionPane.showMessageDialog(frame,
                    nameMap.getName("Map isn't calculable T_T"),
                    nameMap.getName("WARNING"), JOptionPane.WARNING_MESSAGE);
            return false;
        }
    }
    private MetroFrame frame;
    private NameMap nameMap;
}
